package com.example.parallelandroid;

import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import com.bumptech.glide.Glide;
import com.google.gson.Gson;

public class DataDetailActivity extends AppCompatActivity {
    //定义各种控件
    private TextView detailNickName,detailGender,detailIntelligence,detailPower,detailCharm
            ,detailProvince,detailBirthday,detailComprehensive,detailTodayLearningTime,detailTodayStep,detailBio;
    private ImageView detailAvatar,detailWearWeapon,detailWearSuit;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_data_detail);
        getViews();
        String detailJson=getIntent().getStringExtra("detailJson");
        // Register an adapter to manage the date types as long values
        Gson gson = new Gson();
        Data data=gson.fromJson(detailJson,Data.class);
        detailNickName.setText(data.getNickName());
        if(data.getGender()==null){
            detailGender.setText("未设置");
        }else{
            detailGender.setText(data.getGender());
        }
        detailIntelligence.setText(data.getIntelligence()+"");
        detailPower.setText(data.getPower()+"");
        detailCharm.setText(data.getCharm()+"");
        String avatar=data.getAvatar();
        switch (avatar){
            case "1":
                Glide.with(this).load(R.mipmap.tou1).into(detailAvatar);
                break;
            case "2":
                Glide.with(this).load(R.mipmap.tou2).into(detailAvatar);
                break;
            case "3":
                Glide.with(this).load(R.mipmap.tou3).into(detailAvatar);
                break;
            case "4":
                Glide.with(this).load(R.mipmap.tou4).into(detailAvatar);
                break;
            case "5":
                Glide.with(this).load(R.mipmap.tou5).into(detailAvatar);
                break;
            case "6":
                Glide.with(this).load(R.mipmap.tou6).into(detailAvatar);
                break;
            case "7":
                Glide.with(this).load(R.mipmap.tou7).into(detailAvatar);
                break;
            case "8":
                Glide.with(this).load(R.mipmap.tou8).into(detailAvatar);
                break;
            case "9":
                Glide.with(this).load(R.mipmap.tou9).into(detailAvatar);
                break;
            case "10":
                Glide.with(this).load(R.mipmap.tou10).into(detailAvatar);
                break;
            case "11":
                Glide.with(this).load(R.mipmap.tou11).into(detailAvatar);
                break;
            case "12":
                Glide.with(this).load(R.mipmap.tou12).into(detailAvatar);
                break;
        }
        Glide.with(this).load(data.getWearWeapon()).into(detailWearWeapon);
        Glide.with(this).load(data.getWearSuit()).into(detailWearSuit);
        if(data.getProvince()==null){
            detailProvince.setText("未设置");
        }else{
            detailProvince.setText(data.getProvince());
        }
        if(data.getBirthday()==null){
            detailBirthday.setText("未设置");
        }else{
            detailBirthday.setText(data.getBirthday()+"");
        }
        detailComprehensive.setText(data.getComprehensive()+"");
        detailTodayLearningTime.setText(data.getTodayLearningTime()+"");
        detailTodayStep.setText(data.getTodayStep()+"");
        if(data.getBio()!=null){
            detailBio.setText(data.getBio());
        }else{
            detailBio.setText("这个人很懒,什么都没有留下");
        }
    }

    private void getViews() {
        detailNickName=findViewById(R.id.detail_nick_name);
        detailGender=findViewById(R.id.detail_gender);
        detailAvatar=findViewById(R.id.detail_avatar);
        detailIntelligence=findViewById(R.id.detail_intelligence);
        detailPower=findViewById(R.id.detail_power);
        detailCharm=findViewById(R.id.detail_charm);
        detailWearWeapon=findViewById(R.id.detail_wear_weapon);
        detailWearSuit=findViewById(R.id.detail_wear_suit);
        detailProvince=findViewById(R.id.detail_province);
        detailBirthday=findViewById(R.id.detail_birthday);
        detailComprehensive=findViewById(R.id.detail_comprehensive);
        detailTodayLearningTime=findViewById(R.id.detail_today_learning_time);
        detailTodayStep=findViewById(R.id.detail_today_step);
        detailBio=findViewById(R.id.detail_bio);
    }
}